use TeO, clear

// standardize items
foreach x in relimp r_ostent r_miam r_impedu r_culte feelfrench seenasfrench homeinfrance french_fam french_sp french_kids {
	sum `x', det
	gen `x'_st=(`x'-r(mean))/r(sd)
}

egen avg_rel=rowmean(relimp_st r_ostent_st r_miam_st r_impedu_st r_culte_st)

egen avg_assim=rowmean(feelfrench_st seenasfrench_st homeinfrance_st)

egen avg_lan=rowmean(french_fam french_sp french_kids)

// Predicted devoutness/assimilation using predictors identified by lasso2 
reg avg_lan muslimm frenchm frenchbirth frenchathome turkeyf roafricaf 
predict lingassim_2, xb

reg avg_rel muslimm frenchm 
predict devoutness_avg_2, xb

reg avg_assim muslimm frenchathome roafricaf 
predict assimilation_2, xb

//Regressions
estimates clear

reg secondary i.birthyear##c.devoutness_avg_2 i.religion##c.devoutness_avg_2 tmuslim devoutness_avg_2  interm##c.devoutness_avg_2 if bpl=="1101" &female==1&agenq>=20, cl(religion)
eststo m1

reg secondary i.birthyear##c.assimilation_2 i.religion##c.assimilation_2 tmuslim assimilation_2  interm##c.assimilation_2 if bpl=="1101" &female==1&agenq>=20, cl(religion)
eststo m2

reg secondary i.birthyear##c.lingassim_2 i.religion##c.lingassim_2 tmuslim lingassim_2  interm##c.lingassim_2 if bpl=="1101" &female==1&agenq>=20, cl(religion)
eststo m3

esttab m* using "Table4.csv", star(+ 0.1 * 0.05 ** 0.01 *** 0.001) replace ///
		cells(b(fmt(a3) star) se(par)) stats(N r2)  ///
		keep(1.interm 1.interm#c*) 
